//选择某一行
var C445TN_select_info_schema_rowId = "";
//按钮事件新增或编辑
var C445TN_type = "";
//其他页面传到本页面参数
var C445TN_param = {};

/*定义查询条件变量*/
/*declare query param begin*/

var C445TN_tem_DB_ID = "";
var C445TN_tem_TABLE_TYPE = "";
/*declare query param end*/

/*定义下拉框集合定义*/
/*declare select options begin*/

var C445TN_ary_DB_ID = null;
var C445TN_ary_TABLE_TYPE = [{'MAIN_ID': '0', 'CN_NAME': '表'}, {'MAIN_ID': '1', 'CN_NAME': '视图'}];
/*declare select options end*/

//主从表传递参数
function C445TN_param_set(){
	/*Main Subsuv Table Param Begin*/
	
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function C445TN_info_schema_biz_start(inputparam) {
	layer.close(ly_index);
	C445TN_param = inputparam;
	//主从表传递参数
	C445TN_param_set();	
    /*biz begin*/

    if($("#C445TN_qry_TABLE_TYPE").is("select") && $("#C445TN_qry_TABLE_TYPE")[0].options.length == 0)
    {
        $.each(C445TN_ary_TABLE_TYPE, function (i, obj) {
            addOptionValue("C445TN_qry_TABLE_TYPE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
        });
    }
    
    var inputdata = {
            "param_name": "A01_INFSCH",
            "session_id": session_id,
            "login_id": login_id,
            "param_value1": "",
            "param_value2": "0"
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "C445TN_A01_INFSCH");
    /*biz end*/
}

/*业务函数步骤*/
/*biz step begin*/
function C445TN_format_TABLE_TYPE(value, row, index) {
    var objResult = value;
    for(i = 0; i < C445TN_ary_TABLE_TYPE.length; i++) {
        var obj = C445TN_ary_TABLE_TYPE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function C445TN_A01_INFSCH(input) {
    layer.close(ly_index);
    //查询失败
    if (Call_QryResult(input.A01_INFSCH) == false)
        return false;
    C445TN_ary_DB_ID = input.DB_ID;    
    if($("#C445TN_qry_DB_ID").is("select") && $("#C445TN_qry_DB_ID")[0].options.length == 0)
    {
        $.each(C445TN_ary_DB_ID, function (i, obj) {
            addOptionValue("C445TN_qry_DB_ID", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
        });
    }
    
    C445TN_init_info_schema();
}
/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

/*find qry fun end*/

/*页面结束*/
function C445TN_page_end(){
	page_btn_priv("C445TN");
	C445TN_adjust_tab();
}

//获取数据接口视图显示列定义
var C445TN_info_schema = [
	{ 
		checkbox:true
	},
	/*table column begin*/

    {
        title: '主键',
        field: 'MAIN_ID',
        sortable: true,
        visible: false
    },
    {
        title: '数据源',
        field: 'DB_CN_NAME',
        sortable: true
        ,formatter: set_s_decode
    },
    {
        title: '数据源ID',
        field: 'DB_MAIN_ID',
        visible: false
    },
    {
        title: '表或视图名',
        field: 'TABLE_NAME',
        sortable: true
        ,formatter: set_s_decode
    },
    {
        title: '表或视图类型',
        field: 'TABLE_TYPE',
        sortable: true
        ,formatter: C445TN_format_TABLE_TYPE
    }
	/*table column end*/
];

//页面初始化
function C445TN_init_info_schema() {
	$(window).resize(function () {
		  $('#C445TN_info_schema_Events').bootstrapTable('resetView');
	});
	//获取数据接口视图查询条件初始化设置
	/*query conditions init begin*/
	C445TN_tem_DB_ID = $("#C445TN_qry_DB_ID").val();
	C445TN_tem_TABLE_TYPE = $("#C445TN_qry_TABLE_TYPE").val();
    /*query conditions init end*/
	
	$('#C445TN_btn_info_schema_query').click();
}

//查询接口
function C445TN_info_schema_query() {
    $('#C445TN_info_schema_Events').bootstrapTable("removeAll");
	//以下为特殊字段列表查询，无特殊字段时不需要
	var inputdata = {
		"param_name": "A01_INFSCH",
		"session_id": session_id,
		"login_id": login_id
		/*传递查询条件变量*/
        /*get query param begin*/

        ,"param_value1": C445TN_tem_DB_ID
        ,"param_value2": C445TN_tem_TABLE_TYPE	
        /*get query param end*/
	};
	ly_index = layer.load();
	get_ajax_baseurl(inputdata, "C445TN_get_A01_INFSCH");
}

//查询结果
function C445TN_get_A01_INFSCH(input) {
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.A01_INFSCH) == false)
        return false;
    //调整table各列宽度
    $.each(C445TN_info_schema, function (i, obj) {
		if(obj.title != undefined){
			obj.width = obj.title.length * 14 + 37;
		}
	});
    
	var s_data = input.A01_INFSCH;
    C445TN_select_info_schema_rowId = "";
    if(s_data.length > 0){
    	C445TN_rowCheckData = s_data[0]; 
    }
    //table对应的属性
    var temTableAtt = {};
    temTableAtt["url"] = null;
    temTableAtt["method"] = null;
    temTableAtt["sidePagination"] = null;
    temTableAtt["queryParamsType"] = null;
    $('#C445TN_info_schema_Events').bootstrapTable('destroy');
    $("#C445TN_info_schema_Events").bootstrapTable({
        uniqueId: 'main_id',
        search: !0,
        pagination: !0,
        showRefresh: !0,
        showToggle: !0,
        locale: "zh-CN",
        showColumns: !0,
        showExport: !0,
        exportDataType:"all",
        exportTypes:['excel'],
        iconSize: "outline",
        onClickRow: function (row, $element) {
            // 判断是否已选中
            if ($($element).hasClass("changeColor")) {
                $('#C445TN_info_schema_Events').find("tr.changeColor").removeClass('changeColor');
                C445TN_select_info_schema_rowId = "";
            }
            else {
                // 未点击则，为当前行添加 class='changeColor'
                $('#C445TN_info_schema_Events').find("tr.changeColor").removeClass('changeColor');
                $($element).addClass('changeColor');                　
                C445TN_select_info_schema_rowId = $element.attr('data-index');
                
                //设置子表查询条件
                /*set child table qry begin*/
                
                $($("#C445TN_TAB_MAIN").find(".active")[0]).click();
                /*set child table qry end*/
                //判断是否button按钮点击事件
        		if(typeof($("#C445TN_TAB_MAIN").find(".active")[0]) == "undefined" && C445TN_prev_btn != C445TN_btn){
        			C445TN_prev_btn = C445TN_btn;
        			if($("#"+C445TN_btn)[0] == undefined)
        				eval(C445TN_btn + "()");
        			else
        				$("#"+C445TN_btn).click();
        		}
            }
        },
		onDblClickRow: function (row){
			$('#C445TN_btn_info_schema_load').click();
//			if(C445TN_param.hasOwnProperty("target_name"))
//			{
//				$("#"+C445TN_param["target_id"]).val(eval("row."+C445TN_param["sourc_id"].toUpperCase()));
//				$("#"+C445TN_param["target_name"]).val(s_decode(eval("row."+C445TN_param["sourc_name"].toUpperCase())));				
//				layer.close(C445TN_param["ly_index"]);
//			}
		},
        toolbar: "#C445TN_info_schema_Toolbar",
        url: temTableAtt["url"],
        method: temTableAtt["method"],
        height:500,
        columns: C445TN_info_schema,
        data: s_data,
        pageNumber: 1,
        pageSize: 10, // 每页的记录行数（*）
        pageList: [10,50,100,1000,2000], // 可供选择的每页的行数（*）
        queryParams: C445TN_info_schema_queryParams,
        sidePagination: temTableAtt["sidePagination"],//"server", //服务端处理分页
	    queryParamsType : temTableAtt["queryParamsType"],//"limit",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
        icons: {
            refresh: "glyphicon-repeat",
            toggle: "glyphicon-list-alt",
            columns: "glyphicon-list"
		},
    });
    C445TN_page_end();
}

//设置参数
function C445TN_info_schema_queryParams(inputdata){
	return inputdata;
}

//获取接口数据
function C445TN_Res_N01_sel_info_schema(input){
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.A01_INFSCH) == false)
        return false;
    if(input["A01_INFSCH"].length > 0)
    	C445TN_rowCheckData = input["A01_INFSCH"][0];
    if(C445TN_table_page == 0)
		return null;
	else{ 
		var json_list = {};
		json_list["total"] = input["A01_INFSCH_ROWS"];
		json_list["rows"] = input["A01_INFSCH"];
		return json_list;
	}
}

//刷新按钮
$('#C445TN_btn_info_schema_refresh').click(function () {
	/*重置查询条件变量*/
	/*refresh query param begin*/

    C445TN_tem_INF_CN_NAME = "";
    C445TN_tem_INF_EN_NAME = "";
    C445TN_tem_IS_AUTHORITY = "0";
	/*refresh query param end*/

	/*重置下拉框集合定义*/
	/*refresh select options begin*/

	/*refresh select options end*/
	
	/*页面重置重新加载*/
	/*biz begin*/
    C445TN_init_info_schema();
    /*biz end*/
})

//查询按钮
$('#C445TN_btn_info_schema_query').click(function () {
	/*设置查询条件变量*/
    /*set query param begin*/

    C445TN_tem_DB_ID = $("#C445TN_qry_DB_ID").val();
    C445TN_tem_TABLE_TYPE = $("#C445TN_qry_TABLE_TYPE").val();
    /*set query param end*/
	C445TN_info_schema_query();
})

//vue回调
function C445TN_info_schema_call_vue(objResult){
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	
	/*get find subvue end*/
	
	/*tab页显示子页面*/
	/*get tab subvue begin*/

	/*get tab subvue end*/
}

//加载数据表信息
$('#C445TN_btn_info_schema_load').click(function () {
	//单行选择
	var rowData = $("#C445TN_info_schema_Events").bootstrapTable('getData')[C445TN_select_info_schema_rowId];
	//多行选择
	var rowDatas = C445TN_sel_row_info_schema();
	if (C445TN_select_info_schema_rowId != "" || rowDatas.length > 0) {
        if(rowDatas.length > 0)
        {
	       	$.each(rowDatas, function (i, obj) {
	       		var inputdata = {
					"param_name": "A01_ADDSCH",
					"session_id": session_id,
					"login_id": login_id,
					"param_value1": obj.DB_MAIN_ID,
					"param_value2": s_encode(obj.TABLE_NAME),	
					"param_value3": obj.TABLE_TYPE,				
				};
				ly_index = layer.load();
				get_ajax_baseurl(inputdata, "C445TN_A01_ADDSCH");  			
	       	});
	       	
        }
        else
        {
        	var inputdata = {
				"param_name": "A01_ADDSCH",
				"session_id": session_id,
				"login_id": login_id,
				"param_value1": rowData.DB_MAIN_ID,
				"param_value2": s_encode(rowData.TABLE_NAME),	
				"param_value3": rowData.TABLE_TYPE,				
			};
			ly_index = layer.load();
			get_ajax_baseurl(inputdata, "C445TN_A01_ADDSCH"); 
        }
    } else {
    	swal({
            title: "提示信息",
            text: "无法加载记录，请选择正确记录加载!"
        });
    }
})

//加载数据结果
function C445TN_A01_ADDSCH(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.A01_ADDSCH) == true)
	{
		swal("加载数据成功!", "", "success");
		A12594_init_t_single_table();
		layer.close(C445TN_param["ly_index"]);
	}
}

//主从表选项卡动态添加
function C445TN_adjust_tab(){
	if(typeof($("#C445TN_TAB_MAIN")[0]) != "undefined" && $("#C445TN_TAB_MAIN")[0].length != 0){
		C445TN_Flag = "1";
		$(Get_RDivNoBuild("C445TN","")).find(".wrapper-content").css("padding","20px 20px 0px 20px");
		$(Get_RDivNoBuild("C445TN","")).find(".ibox").css("margin-bottom","0px");
		$(Get_RDivNoBuild("C445TN","")).find(".ibox-content").css("padding","15px 20px 0px");		
		$($("#C445TN_TAB_MAIN").find(".active")[0]).click();
	}
}

/*tab选项卡按钮点击事件*/
/*Tab Click Fun Begin*/

/*Tab Click Fun End*/

//清除 查找框
function C445TN_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//选择多行数据进行业务操作
function C445TN_sel_row_info_schema(){
	//获得选中行
	var checkedbox= $("#C445TN_info_schema_Events").bootstrapTable('getSelections'); 
	//将选中行数据转成jsonStr
	var jsonStr=JSON.stringify(checkedbox);
	//将jsonStr转成jsonObject对象	 
	var jsonObject=jQuery.parseJSON(jsonStr);
	return jsonObject;
	//接着就可以遍历jsonObject数组对象，取出并操作数据
	//alert(jsonObject);
}
